package edu.nuist.studentadmin.dao.impl;

import edu.nuist.studentadmin.dao.StudentDao;
import edu.nuist.studentadmin.model.Student;
import edu.nuist.studentadmin.utils.DBHelper;
import edu.nuist.studentadmin.utils.Md5Util;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Classname StudentDaoImpl
 * @Description TODO
 * @Date 2021/12/28 8:39 上午
 * @Created by lqj(1724226325@qq.com)
 */
public class StudentDaoImpl implements StudentDao {
    @Override
    public boolean checkLogin(String userName, String password) {
        DBHelper dbHelper = new DBHelper();
        List params=new ArrayList();
        params.add(userName);
        params.add(Md5Util.md5(password));
        List<Object> query = dbHelper.query("select * from tbl_user where username=? and password=?", params);
        return query.size()>0;
    }

    @Override
    public boolean checkName(String userName) {
        return false;
    }

    @Override
    public boolean save(Student student) {
        return false;
    }

    @Override
    public boolean delete(int stuno) {
        return false;
    }

    @Override
    public boolean update(Student student) {
        return false;
    }

    @Override
    public List<Student> getAllStudents() {
        DBHelper dbHelper = new DBHelper();
        List<Student> students=new ArrayList<>();
        List<Object> query = dbHelper.query("select * from tbl_student",null);
        for(Object o:query){
            Map map=(Map)o;
            students.add(
                    new Student((String)map.get("stuno"),
                            (String)map.get("stuname"),
                            (String) map.get("classes"),
                            (String)map.get("gender"),
                            (String)map.get("department"),
                            (String)map.get("tel"),
                            (String)map.get("dormno"),
                            (String)map.get("photopath")
                            )
            );
        }
        return students;
    }
}
